package com.cy.pj.notice.web.interceptor;

import com.cy.pj.common.exception.ServiceException;
import org.springframework.web.servlet.HandlerInterceptor;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import java.time.LocalTime;

public class TimeAccessInterceptor implements HandlerInterceptor {
    @Override
    public boolean preHandle(HttpServletRequest request, HttpServletResponse response, Object handler) throws Exception {

        System.out.println("==preHandle==");
        LocalTime localTime = LocalTime.now();
        int hour = localTime.getHour();
        System.out.println();
        if (hour < 9 || hour > 18)
            throw new ServiceException("请求指定时间访问");
        return true;
    }
}
